import requests


def querySessionId():
    # 定义要设置的 Cookie
    url = 'https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc'
    r = requests.get(url)
    cookies = r.cookies
    # 提取 JSESSIONID
    jsessionid = cookies.get('JSESSIONID')
    print(jsessionid)

def queryUser():
    # 定义要设置的 Cookie
    cookies = {
      #  '_uab_collina': '173033956278574352963227',
        'JSESSIONID': 'CC32DBBC1E1FBC2F054C950DDF67B367',
      #  'tk': 'AjQflzzmOkFa_rC8JC4Y0GqieRtzmku_gac1c0',
        'BIGipServerotn': '1473839370.64545.0000',
       # 'BIGipServerpassport': '820510986.50215.0000',
       # 'guidesStatus': 'off',
       # 'highContrastMode': 'defaltMode',
       # 'cursorStatus': 'off',
        'route': '9036359bb8a8a461c164a04f8f50b252',
      #  'searchHistory': '%5B%7B%22innerText%22%3A%22%u4E0A%u6D77%22%2C%22url%22%3A%22https%3A//www.12306.cn/index/view/infos/sale_time.html%3Fstation_name%3D%25E4%25B8%258A%25E6%25B5%25B7%26station_code%3DSHH%22%7D%5D',
       # '_jc_save_fromStation': '%u5E38%u5DDE%2CCZH',
      #  '_jc_save_toStation': '%u4E0A%u6D77%2CSHH',
      #  '_jc_save_toDate': '2024-10-31',
      #  '_jc_save_wfdc_flag': 'dc',
     #   'uKey': 'b3ab96aab78067f895a2f4aa3c7b671eae3545f4bef2db806cba2db614b9b8c8',
      #  '_jc_save_fromDate': '2024-10-31'
    }
    queryUrl = 'https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs'
    queryData = {'REPEAT_SUBMIT_TOKEN': '5cd5cd6e061ed30f0d1c461c1f57b8df','_json_att':''}
    response = requests.post(queryUrl, json=queryData,cookies= cookies)
    print(response.status_code)
    print(response.text)

if __name__ == '__main__':
    #queryUser()
    querySessionId()
